/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project.jpdftools.ui.actionlisteners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import javax.swing.undo.UndoManager;
import project.jpdftools.ui.logic.JPDF;
import project.jpdftools.ui.logic.JPDFText;
import project.jpdftools.managers.LoggerManager;

/**
 *
 * @author Mido
 */
public class RedoAction implements ActionListener {

    private JPDF component;
    private UndoManager undo_manager;

    public RedoAction(JPDF component, UndoManager undo_manager) {
        super();
        this.component = component;
        this.undo_manager = undo_manager;

        // check if you can redo
        if (undo_manager.canRedo() == false) {
            ((JPDFText) component).getMiRedo().setEnabled(false);
        }
    }

    public void actionPerformed(ActionEvent evt) {
        // make sure that the component is not visible
        if (component instanceof JPDFText) {
            JPDFText text = (JPDFText) component;
            // check if the action can be redone
            if (undo_manager.canRedo()) {
                // enable undo menu item
                text.getMiUndo().setEnabled(true);
                // redo the action
                undo_manager.redo();

                // check if you cann't redo
                if (undo_manager.canRedo() == false) {
                    text.getMiRedo().setEnabled(false);
                }
                LoggerManager.getLogger().log(Level.INFO, "Action redone on component. Component ID = {0}", text.getId());
            } else {
                text.getMiRedo().setEnabled(false);
            }
        }
    }
}
